package com.pagoda.nerp.trade.common;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.pagoda.nerp.trade.common.enums.ErrorCodeMappingEnums;

/**
 * Created by Jungle on 2016/12/13.
 */
@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)
public class BaseResult<T> {

    private int errorCode ;
    private T data;
    private String errorMsg;

    /**
     * 构建基本返回对象结果
     * @param errorCodeMappingEnums 错误码枚举定义
     * @param data 响应数据对象
     */
    public BaseResult(ErrorCodeMappingEnums errorCodeMappingEnums, T data) {
        this.errorCode = errorCodeMappingEnums.getErrorCode();
        this.data = data;
        this.errorMsg = errorCodeMappingEnums.getErrorMsg();
    }

    public BaseResult(int errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    /**
     * 自定义返回消息信息
     * @param errorCodeMappingEnums
     * @param message
     */
    public BaseResult(ErrorCodeMappingEnums errorCodeMappingEnums,String message) {
        this.errorCode = errorCodeMappingEnums.getErrorCode();
        this.errorMsg = message ;
    }

    public BaseResult(ErrorCodeMappingEnums errorCodeMappingEnums) {
        this.errorCode = errorCodeMappingEnums.getErrorCode();
        this.errorMsg = errorCodeMappingEnums.getErrorMsg();
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

}
